const Koa = require('koa');
const Router = require('koa-router');
const bodyParser = require('koa-bodyparser');

const config = require('./app/config')
const {
  getFieldsList,
  getquestionsRand,
  getquestionsById,
  getScoreList,
  getScoreById,
  addScore
} = require('./controller/user.controller');

const app = new Koa();

const userRouter = new Router();

userRouter.get('/fields', getFieldsList)

userRouter.get('/questions', getquestionsRand)
userRouter.post('/questions', getquestionsById)

userRouter.get('/scores', getScoreList)
userRouter.get('/scores/:id', getScoreById)
userRouter.post('/scores', addScore)

app.use(bodyParser());
app.use(userRouter.routes());
app.use(userRouter.allowedMethods());

app.listen(config.APP_PORT, () => {
  console.log("在线答题小程序服务器启动成功");
})
